<?php
// file : ajax_country.php
include_once "inc_function.php";

function list_all($con){
      $curs = oci_new_cursor($con);
   	$stmt = OCIParse($con,"begin pkg_master.sp_get_country_list(1,:o_country_list); end;");
   	OCIBindByName($stmt,":o_country_list",&$curs,-1,OCI_B_CURSOR);
   	ociexecute($stmt,OCI_DEFAULT);
   	ociexecute($curs,OCI_DEFAULT);
   	return $curs;
      oci_free_statement($stmt);
}

switch($_POST['condition']){
   case "delete" :
         $record = oci_parse($con,"begin pkg_master.sp_delete_m_country(:country_id);end;");
         oci_bind_by_name($record, ':country_id',$_POST['record']);
         oci_execute($record,OCI_DEFAULT);

         $curs = list_all($con);
         $i = 1;
         while (OCIFetchInto($curs,&$o_country_list)){
         ?>
                <tr>
                  <td> <?= $i ?> </td>
                  <td> <?= $o_country_list[0];?> </td>
                  <td> <?= $o_country_list[1];?> </td>
                  <td> <?= $o_country_list[4];?> </td>
                  <td>
                  <a class="btn" href="form_country.php?form=update&update=<?= $o_country_list[0];?>"><img src="http://<?= IMAGE_PATH?>gtk-edit.png"/></a>
<!--              <img class="btn" src="http://<?= IMAGE_PATH?>gtk-edit.png">
                  <img class="btn" src="http://<?= IMAGE_PATH?>delete.png" onclick="return onDelete(<?= $o_country_list[0];?>)">-->
                   </td>

               </tr>
         <?php $i++;
         }
         oci_free_statement($record);
   break;
   case "search" :
         $curs = oci_new_cursor($con);
      	$stmt = OCIParse($con,"begin pkg_master.sp_get_country_list_by_name(1,:country_name,:o_country_list); end;");
      	OCIBindByName($stmt,":country_name",$_POST['search']);
      	OCIBindByName($stmt,":o_country_list",&$curs,-1,OCI_B_CURSOR);
      	ociexecute($stmt,OCI_DEFAULT);
      	ociexecute($curs,OCI_DEFAULT);
         $i = 1;
         while (OCIFetchInto($curs,&$o_country_list)){
         ?>
                <tr>
                  <td> <?= $i ?></td>
                  <td> <?= $o_country_list[0];?> </td>
                  <td> <?= $o_country_list[1];?> </td>
                  <td> <?= $o_country_list[4];?> </td>
                  <td>

                  <?php if($o_country_list[0] != "Data not found"){?>
                  <a class="btn" href="form_country.php?form=update&update=<?= $o_country_list[0];?>"><img src="http://<?= IMAGE_PATH?>gtk-edit.png"/></a>
                  <?php }else{ echo "-";} ?>
<!--              <img class="btn" src="http://<?= IMAGE_PATH?>gtk-edit.png">
                  <img class="btn hidden" src="http://<?= IMAGE_PATH?>delete.png" onclick="return onDelete(<?= $o_country_list[0];?>)">
-->
                  </td>
               </tr>
         <?php
         $i++;
         }


         oci_free_statement($stmt);
   break;
   case "page":

   break;
   case "update" :
   break;
   default :
   break;
}
?>